{extend name="platform/base" /}
{block name="resources"/}
<style>
.col-md-2 {
    line-height: 35px;
}
.required{
	color:red;margin-right:10px;
}
.error{
	font-size: 12px;
    line-height: 16px;
    color: red;
    margin-top: 10px;
	display:none;
}
</style>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 添加分组 </header>
	<div class="panel-body">
		<form class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="required">*</span>分组名称</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="group_name" value="">
				</div>
				<p class="error">请输入分组名称</p>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">排序</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="group_sort"
						value="">
				</div>
			</div>
			

			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="addShopGroupAjax()"
						class="btn btn-primary">保存</a>
				</div>
			</div>
		</form>
	</div>
</section>
<script>	
	//添加分组
	function addShopGroupAjax() {
		var group_name = $("#group_name").val();
		var group_sort = $("#group_sort").val();
		if(verify(group_name)){	
		$.ajax({
			type : "post",
			url : "{:__URL('PLATFORM_MAIN/Shop/addShopGroup')}",
			data : {
				'group_name' : group_name,
				'group_sort' : group_sort
			},
			async : true,
			success : function(data) {
				if (data["code"] > 0) {
					showMessage('success', "添加成功","{:__URL('PLATFORM_MAIN/Shop/shopgrouplist')}");
				}else{
					showMessage('error', "添加失败");
				}
			}
		});
	}
}
	function verify(group_name){
		if(group_name == ''){
    		$("#group_name").parent().next(".error").show();
      		$("#group_name").focus();
       		return false;
     	}else{
      		$(".error").hide();
      		return true;
   		 }
	}
</script>
{/block}
